﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using CRM.Entity;
using System.Web.UI.WebControls;

namespace CRM.BLL
{
    [Serializable] 
    public static class ReportHelper
    {
        public static T_BUSINESSDIVISION_BLL _businessdivisionBLL;
        public static T_DEPARTMENT_BLL _departmentBLL;

        /// <summary>
        /// 报表基本元素
        /// </summary>
        public struct myReportEnum
        {
            #region 基本参数
            /// <summary>
            /// 用户编号
            /// </summary>
            public static string UserId = "";
            /// <summary>
            /// 用户姓名
            /// </summary>
            public static string UserName = "";
            /// <summary>
            /// 登录名
            /// </summary>
            public static string LoginName = "";
            /// <summary>
            /// 部门编号
            /// </summary>
            public static string DepartmentId = "";
            /// <summary>
            /// 部门名称
            /// </summary>
            public static string DepartmentName = "";
            /// <summary>
            /// 角色编号
            /// </summary>
            public static string RoleId = "";
            /// <summary>
            /// 角色名称
            /// </summary>
            public static string RoleName = "";
            /// <summary>
            /// 部门人数
            /// </summary>
            public static string DepartCount = "0";
            /// <summary>
            /// 事业部人数
            /// </summary>
            public static string BusinessCount = "0";
            /// <summary>
            /// 统计开始时间（YYYYmmdd）
            /// </summary>
            public static string SDate_Varchar = "";
            /// <summary>
            /// 统计结束时间（YYYYmmdd）
            /// </summary>
            public static string EDate_Varchar = "";
            /// <summary>
            /// 统计开始时间（YYYY-mm-dd HH:mm:ss）
            /// </summary>
            public static string SDate_DateTime = "";
            /// <summary>
            /// 统计结束时间（YYYY-mm-dd HH:mm:ss）
            /// </summary>
            public static string EDate_DateTime = "";
            /// <summary>
            /// 最后显示表记录
            /// </summary>
            public static DataTable pLastTable = new DataTable();
            /// <summary>
            /// 显示用户、部门、事业部的条件
            /// </summary>
            public static string pFilter = "";
            /// <summary>
            /// 人数的累加总数
            /// </summary>
            public static int pTotal = 0;
            /// <summary>
            /// 事业部名称
            /// </summary>
            public static string pBusinessName = "";
            /// <summary>
            /// 事业部编码
            /// </summary>
            public static string pBusinessCode = "";
            /// <summary>
            /// 工单类型
            /// </summary>
            public static string pCaseName = "";
            /// <summary>
            /// Oracle连接字符串
            /// </summary>
            public static string pConnectString = "";

            #endregion
        }

        /// <summary>
        /// 工单统计元素
        /// </summary>
        public struct myCaseEnum
        {
            #region 单体统计
            /// <summary>
            /// 工单总数
            /// </summary>
            public static int nCaseCount;
            /// <summary>
            /// 咨询工单数量
            /// </summary>
            public static int nCousultCaseCount;
            /// <summary>
            /// 报修工单数量
            /// </summary>
            public static int nRepairCaseCount;
            /// <summary>
            /// 投诉工单数量
            /// </summary>
            public static int nComplaintCount;
            /// <summary>
            /// 12小时回访数量
            /// </summary>
            public static int n12CallBack;
            /// <summary>
            /// 24小时回访数量
            /// </summary>
            public static int n24CallBack;
            /// <summary>
            /// 投诉工单48小时回访数量
            /// </summary>
            public static int n48CallBackComplaint;
            /// <summary>
            /// 报修工单48小时回访数量
            /// </summary>
            public static int n48CallBack;
            /// <summary>
            /// 72小时回访数量
            /// </summary>
            public static int n72CallBack;
            /// <summary>
            /// 120小时回访数量
            /// </summary>
            public static int n120CallBack;
            /// <summary>
            /// 120小时回访数量
            /// </summary>
            public static int nOver120CallBack;
            /// <summary>
            /// 未回访数量
            /// </summary>
            public static int nUnCallBack;
            /// <summary>
            /// 回访属实数
            /// </summary>
            public static int nCallBackTrue;
            /// <summary>
            /// 回访不属实数
            /// </summary>
            public static int nCallBackFalse;

            /// <summary>
            /// 12小时内处理量
            /// </summary>
            public static int n12Close;
            /// <summary>
            /// 24小时内闭环数量
            /// </summary>
            public static int n24Close;
            /// <summary>
            /// 48小时内闭环数量
            /// </summary>
            public static int n48Close;
            /// <summary>
            /// 72小时内闭环数量
            /// </summary>
            public static int n72Close;
            /// <summary>
            /// 120小时内闭环数量
            /// </summary>
            public static int n120Close;
            /// <summary>
            /// 120小时以上闭环数量
            /// </summary>
            public static int nOver120Close;
            /// <summary>
            /// 未闭环数量
            /// </summary>
            public static int nUnClose;
            /// <summary>
            /// 工单完成数量
            /// </summary>
            public static int nCompleteCount;
            /// <summary>
            /// 15分钟内回复量
            /// </summary>
            public static int n15MinReplyCount;
            /// <summary>
            /// 1小时出发数量
            /// </summary>
            public static int n1HourGoCount;
            /// <summary>
            /// 4小时出发数量
            /// </summary>
            public static int n4HourArriveCount;
            /// <summary>
            /// 在途总时长（小时）
            /// </summary>
            public static double nOnWayTime;
            /// <summary>
            /// 处理总时长（小时）
            /// </summary>
            public static double nProcessTime;

            /// <summary>
            /// 回访满意度-汇总
            /// </summary>
            public static int nComplaintObject_0;
            /// <summary>
            /// 回访满意度-非常不满意
            /// </summary>
            public static int nComplaintObject_1;
            /// <summary>
            /// 回访满意度-不满意 
            /// </summary>
            public static int nComplaintObject_2;
            /// <summary>
            /// 回访满意度-一般 
            /// </summary>
            public static int nComplaintObject_3;
            /// <summary>
            /// 回访满意度-满意 
            /// </summary>
            public static int nComplaintObject_4;
            /// <summary>
            /// 回访满意度-非常满意 
            /// </summary>
            public static int nComplaintObject_5;
            /// <summary>
            /// 回访结果-是否全面检查 
            /// </summary>
            public static int nComplaintObject_6;
            /// <summary>
            /// 回访结果-是否培训 
            /// </summary>
            public static int nComplaintObject_7;

            /// <summary>
            /// 索赔单数量
            /// </summary>
            public static int nClaimCount;
            /// <summary>
            /// 索赔单通过
            /// </summary>
            public static int nClaimAllow;
            /// <summary>
            /// 索赔单不通过
            /// </summary>
            public static int nClaimRefuse;
            /// <summary>
            /// 索赔单驳回
            /// </summary>
            public static int nClaimBack;
            /// <summary>
            /// 上门维修次数
            /// </summary>
            public static int nClaimArrive;

            /// <summary>
            /// 退回工单量
            /// </summary>
            public static int nReturnCount;
            /// <summary>
            /// 补订单量
            /// </summary>
            public static int nAddCount;

            /// <summary>
            /// 回访满意度
            /// </summary>
            public static int nReturnHappy;
            /// <summary>
            /// 回访不满意度
            /// </summary>
            public static int nReturnNotHappy;
            /// <summary>
            /// 使用服务监督卡
            /// </summary>
            public static int nCardYes;
            /// <summary>
            /// 未使用服务监督卡
            /// </summary>
            public static int nCardNo;

            /// <summary>
            /// 呼入应答量
            /// </summary>
            public static int nAccept;
            /// <summary>
            /// 外呼总量
            /// </summary>
            public static int nOutband;
            /// <summary>
            /// 外呼通话总量
            /// </summary>
            public static int nOutbandConnect;

            /// <summary>
            /// 工单退回量
            /// </summary>
            public static int nCaseBack;
            /// <summary>
            /// 工单再次派工量
            /// </summary>
            public static int nCaseAgain;
            /// <summary>
            /// 工单重新派工量
            /// </summary>
            public static int nCaseAssign;

            #endregion

            #region 汇总统计
            /// <summary>
            /// 工单总数
            /// </summary>
            public static int dtCaseCount;
            /// <summary>
            /// 咨询工单数量
            /// </summary>
            public static int dtCousultCaseCount;
            /// <summary>
            /// 报修工单数量
            /// </summary>
            public static int dtRepairCaseCount;
            /// <summary>
            /// 投诉工单数量
            /// </summary>
            public static int dtComplaintCount;
            /// <summary>
            /// 12小时回访数量
            /// </summary>
            public static int dt12CallBack;
            /// <summary>
            /// 24小时回访数量
            /// </summary>
            public static int dt24CallBack;
            /// <summary>
            /// 48小时回访数量
            /// </summary>
            public static int dt48CallBack;
            /// <summary>
            /// 投诉工单48小时回访数量
            /// </summary>
            public static int dt48CallBackComplaint;
            /// <summary>
            /// 72小时回访数量
            /// </summary>
            public static int dt72CallBack;
            /// <summary>
            /// 120小时回访数量
            /// </summary>
            public static int dt120CallBack;
            /// <summary>
            /// 120小时回访数量
            /// </summary>
            public static int dtOver120CallBack;
            /// <summary>
            /// 未回访数量
            /// </summary>
            public static int dtUnCallBack;
            /// <summary>
            /// 回访属实数
            /// </summary>
            public static int dtCallBackTrue;
            /// <summary>
            /// 回访不属实数
            /// </summary>
            public static int dtCallBackFalse;

            /// <summary>
            /// 12小时内处理量
            /// </summary>
            public static int dt12Close;
            /// <summary>
            /// 24小时内闭环数量
            /// </summary>
            public static int dt24Close;
            /// <summary>
            /// 48小时内闭环数量
            /// </summary>
            public static int dt48Close;
            /// <summary>
            /// 72小时内闭环数量
            /// </summary>
            public static int dt72Close;
            /// <summary>
            /// 120小时内闭环数量
            /// </summary>
            public static int dt120Close;
            /// <summary>
            /// 120小时以上闭环数量
            /// </summary>
            public static int dtOver120Close;
            /// <summary>
            /// 未闭环数量
            /// </summary>
            public static int dtUnClose;

            /// <summary>
            /// 工单完成数量
            /// </summary>
            public static int dtCompleteCount;

            /// <summary>
            /// 15分钟内回复量
            /// </summary>
            public static int dt15MinReplyCount;
            /// <summary>
            /// 1小时出发数量
            /// </summary>
            public static int dt1HourGoCount;
            /// <summary>
            /// 4小时出发数量
            /// </summary>
            public static int dt4HourArriveCount;
            /// <summary>
            /// 在途总时长（小时）
            /// </summary>
            public static double dtOnWayTime;
            /// <summary>
            /// 处理总时长（小时）
            /// </summary>
            public static double dtProcessTime;

            /// <summary>
            /// 回访满意度-汇总
            /// </summary>
            public static int dtComplaintObject_0;
            /// <summary>
            /// 回访满意度-非常不满意
            /// </summary>
            public static int dtComplaintObject_1;
            /// <summary>
            /// 回访满意度-不满意 
            /// </summary>
            public static int dtComplaintObject_2;
            /// <summary>
            /// 回访满意度-一般 
            /// </summary>
            public static int dtComplaintObject_3;
            /// <summary>
            /// 回访满意度-满意 
            /// </summary>
            public static int dtComplaintObject_4;
            /// <summary>
            /// 回访满意度-非常满意 
            /// </summary>
            public static int dtComplaintObject_5;
            /// <summary>
            /// 回访结果-是否全面检查 
            /// </summary>
            public static int dtComplaintObject_6;
            /// <summary>
            /// 回访结果-是否培训 
            /// </summary>
            public static int dtComplaintObject_7;

            /// <summary>
            /// 索赔单数量
            /// </summary>
            public static int dtClaimCount;
            /// <summary>
            /// 索赔单通过
            /// </summary>
            public static int dtClaimAllow;
            /// <summary>
            /// 索赔单不通过
            /// </summary>
            public static int dtClaimRefuse;
            /// <summary>
            /// 索赔单驳回
            /// </summary>
            public static int dtClaimBack;
            /// <summary>
            /// 上门维修次数
            /// </summary>
            public static int dtClaimArrive;

            /// <summary>
            /// 退回工单量
            /// </summary>
            public static int dtReturnCount;
            /// <summary>
            /// 补订单量
            /// </summary>
            public static int dtAddCount;

            /// <summary>
            /// 回访满意度
            /// </summary>
            public static int dtReturnHappy;
            /// <summary>
            /// 回访不满意度
            /// </summary>
            public static int dtReturnNotHappy;
            /// <summary>
            /// 使用服务监督卡
            /// </summary>
            public static int dtCardYes;
            /// <summary>
            /// 未使用服务监督卡
            /// </summary>
            public static int dtCardNo;

            /// <summary>
            /// 呼入应答量
            /// </summary>
            public static int dtAccept;
            /// <summary>
            /// 外呼总量
            /// </summary>
            public static int dtOutband;
            /// <summary>
            /// 外呼通话总量
            /// </summary>
            public static int dtOutbandConnect;

            /// <summary>
            /// 工单退回量
            /// </summary>
            public static int dtCaseBack;
            /// <summary>
            /// 工单再次派工量
            /// </summary>
            public static int dtCaseAgain;
            /// <summary>
            /// 工单重新派工量
            /// </summary>
            public static int dtCaseAssign;

            #endregion
        }

        #region 计算平均值、率

        /// <summary>
        /// 将时间格式转化为00:00:00显示
        /// </summary>
        /// <param name="s">数值（单位为秒）</param>
        /// <returns>DateTime格式</returns>
        public static string ConvertToDateTimeFormat(double s)
        {
            string temp = "";
            s = Math.Abs(s);
            if (s >= 3600)
            {
                temp += ((int)(s / 3600)).ToString().PadLeft(2, '0');
                s = s % 3600;
            }
            else
            {
                temp += "00";
            }
            temp += ":";
            if (s >= 60 && s < 3600)
            {
                temp += ((int)(s / 60)).ToString().PadLeft(2, '0');
                s = s % 60;
            }
            else
            {
                temp += "00";
            }
            temp += ":" + s.ToString().PadLeft(2, '0'); ;
            return temp.ToString();
        }

        /// <summary>
        /// 将时间格式转化为小时显示
        /// </summary>
        /// <param name="s">数值（单位为小时）</param>
        /// <returns></returns>
        public static string ConvertToHourFormat(double hour)
        {
            string temp = string.Empty;
            double dTemp = 0;
            hour = Math.Abs(hour);

            if (hour == 0)
                temp = "0.00";
            else
            {
                dTemp = Math.Round(hour / 3600, 3);
                temp = dTemp.ToString();
            }
            return temp;
        }

        /// <summary>
        /// 将时间格式转化为分钟显示
        /// </summary>
        /// <param name="s">数值（单位为分钟）</param>
        /// <returns></returns>
        public static string ConvertToMinutFormat(double minut)
        {
            string temp = string.Empty;
            double dTemp = 0;
            minut = Math.Abs(minut);

            if (minut == 0)
                temp = "0.00";
            else
            {
                dTemp = Math.Round(minut / 60, 3);
                temp = dTemp.ToString();
            }
            return temp;
        }

        /// <summary>
        /// 计算比率
        /// </summary>
        /// <param name="a"></param>
        /// <param name="b"></param>
        /// <returns></returns>
        public static double AccountRate(int a, int b)
        {
            double dTemp;
            if (a <= 0 || b <= 0)
                dTemp = 0.00;
            else
                dTemp = Math.Round(double.Parse(a.ToString()) * 100 / b, 2);
            return dTemp;
        }

        /// <summary>
        /// 计算比率
        /// </summary>
        /// <param name="a"></param>
        /// <param name="b"></param>
        /// <returns></returns>
        public static double AccountRate(double a, double b)
        {
            double dTemp;
            if (a <= 0 || b <= 0)
                dTemp = 0.00;
            else
                dTemp = Math.Round(a * 100 / b, 2);
            return dTemp;
        }

        /// <summary>
        /// 取平均值（截取小数点2位）
        /// </summary>
        /// <param name="a"></param>
        /// <param name="b"></param>
        /// <returns></returns>
        public static double AccountAvarage(int a, int b)
        {
            double dTemp;
            if (a <= 0 || b <= 0)
                dTemp = 0.00;
            else
                dTemp = Math.Round(double.Parse(a.ToString()) / b, 2);
            return dTemp;
        }

        /// <summary>
        /// 取平均值（截取小数点2位）
        /// </summary>
        /// <param name="a"></param>
        /// <param name="b"></param>
        /// <returns></returns>
        public static double AccountAvarage(double a, int b)
        {
            double dTemp;
            if (a <= 0 || b <= 0)
                dTemp = 0.00;
            else
                dTemp = Math.Round(a / b, 2);
            return dTemp;
        }

        /// <summary>
        /// 取平均值（截取小数点2位）
        /// </summary>
        /// <param name="a"></param>
        /// <param name="b"></param>
        /// <returns></returns>
        public static double AccountAvarage(double a, double b)
        {
            double dTemp;
            if (a <= 0 || b <= 0)
                dTemp = 0.00;
            else
                dTemp = Math.Round(a / b, 2);
            return dTemp;
        }

        #endregion

        /**
        /// <summary>
        /// 工单报表列表
        /// </summary>
        public struct myCaseReport
        {
            public static void 工单分类报表(GridView myGrid)
            {
                #region 加载报表抬头

                ReportHelper.myReportEnum.pLastTable = new DataTable();
                ReportHelper.myReportEnum.pLastTable.Clear();
                ReportHelper.myReportEnum.pLastTable.Columns.Clear();

                ReportHelper.myReportEnum.pLastTable.Columns.Add("事业部");
                ReportHelper.myReportEnum.pLastTable.Columns.Add("工单类型");
                ReportHelper.myReportEnum.pLastTable.Columns.Add("经销商");
                ReportHelper.myReportEnum.pLastTable.Columns.Add("服务商");
                ReportHelper.myReportEnum.pLastTable.Columns.Add("数量");

                #endregion
            }

            public void 投诉率报表(GridView myGrid)
            {
                #region 加载报表抬头

                ReportHelper.myReportEnum.pLastTable = new DataTable();
                ReportHelper.myReportEnum.pLastTable.Clear();
                ReportHelper.myReportEnum.pLastTable.Columns.Clear();

                ReportHelper.myReportEnum.pLastTable.Columns.Add("事业部");
                ReportHelper.myReportEnum.pLastTable.Columns.Add("工单数量");
                ReportHelper.myReportEnum.pLastTable.Columns.Add("投诉工单数量");
                ReportHelper.myReportEnum.pLastTable.Columns.Add("投诉率");

                #endregion
            }

            public void 投诉类型报表(GridView myGrid)
            {
                #region 加载报表抬头

                ReportHelper.myReportEnum.pLastTable = new DataTable();
                ReportHelper.myReportEnum.pLastTable.Clear();
                ReportHelper.myReportEnum.pLastTable.Columns.Clear();

                ReportHelper.myReportEnum.pLastTable.Columns.Add("投诉类型");
                ReportHelper.myReportEnum.pLastTable.Columns.Add("工单数量");
                ReportHelper.myReportEnum.pLastTable.Columns.Add("48小时回访数量");
                ReportHelper.myReportEnum.pLastTable.Columns.Add("属实");
                ReportHelper.myReportEnum.pLastTable.Columns.Add("不属实");

                #endregion
            }

            public void 工单回访情况报表(GridView myGrid)
            {
                #region 加载报表抬头

                ReportHelper.myReportEnum.pLastTable = new DataTable();
                ReportHelper.myReportEnum.pLastTable.Clear();
                ReportHelper.myReportEnum.pLastTable.Columns.Clear();

                ReportHelper.myReportEnum.pLastTable.Columns.Add("事业部");

                ReportHelper.myReportEnum.pLastTable.Columns.Add("工单类型");
                ReportHelper.myReportEnum.pLastTable.Columns.Add("工单数量");
                ReportHelper.myReportEnum.pLastTable.Columns.Add("48小时回访数量");
                ReportHelper.myReportEnum.pLastTable.Columns.Add("属实");
                ReportHelper.myReportEnum.pLastTable.Columns.Add("不属实");

                #endregion
            }

            public void 工单闭环情况报表(GridView myGrid)
            {
                #region 加载报表抬头

                ReportHelper.myReportEnum.pLastTable = new DataTable();
                ReportHelper.myReportEnum.pLastTable.Clear();
                ReportHelper.myReportEnum.pLastTable.Columns.Clear();

                ReportHelper.myReportEnum.pLastTable.Columns.Add("事业部");

                ReportHelper.myReportEnum.pLastTable.Columns.Add("工单类型");
                ReportHelper.myReportEnum.pLastTable.Columns.Add("工单数量");
                ReportHelper.myReportEnum.pLastTable.Columns.Add("48小时回访数量");
                ReportHelper.myReportEnum.pLastTable.Columns.Add("属实");
                ReportHelper.myReportEnum.pLastTable.Columns.Add("不属实");

                #endregion
            }

            public void 工单回访满意度报表(GridView myGrid)
            {
                #region 加载报表抬头

                ReportHelper.myReportEnum.pLastTable = new DataTable();
                ReportHelper.myReportEnum.pLastTable.Clear();
                ReportHelper.myReportEnum.pLastTable.Columns.Clear();

                ReportHelper.myReportEnum.pLastTable.Columns.Add("事业部");

                ReportHelper.myReportEnum.pLastTable.Columns.Add("工单类型");
                ReportHelper.myReportEnum.pLastTable.Columns.Add("工单数量");
                ReportHelper.myReportEnum.pLastTable.Columns.Add("48小时回访数量");
                ReportHelper.myReportEnum.pLastTable.Columns.Add("属实");
                ReportHelper.myReportEnum.pLastTable.Columns.Add("不属实");

                #endregion
            }

            public void 工单回访不满意原因报表(GridView myGrid)
            {
                #region 加载报表抬头

                ReportHelper.myReportEnum.pLastTable = new DataTable();
                ReportHelper.myReportEnum.pLastTable.Clear();
                ReportHelper.myReportEnum.pLastTable.Columns.Clear();

                ReportHelper.myReportEnum.pLastTable.Columns.Add("事业部");

                ReportHelper.myReportEnum.pLastTable.Columns.Add("工单类型");
                ReportHelper.myReportEnum.pLastTable.Columns.Add("工单数量");
                ReportHelper.myReportEnum.pLastTable.Columns.Add("48小时回访数量");
                ReportHelper.myReportEnum.pLastTable.Columns.Add("属实");
                ReportHelper.myReportEnum.pLastTable.Columns.Add("不属实");

                #endregion
            }

            public void 工单及时回访率报表(GridView myGrid)
            {
                #region 加载报表抬头

                ReportHelper.myReportEnum.pLastTable = new DataTable();
                ReportHelper.myReportEnum.pLastTable.Clear();
                ReportHelper.myReportEnum.pLastTable.Columns.Clear();

                ReportHelper.myReportEnum.pLastTable.Columns.Add("事业部");

                ReportHelper.myReportEnum.pLastTable.Columns.Add("工单类型");
                ReportHelper.myReportEnum.pLastTable.Columns.Add("工单数量");
                ReportHelper.myReportEnum.pLastTable.Columns.Add("48小时回访数量");
                ReportHelper.myReportEnum.pLastTable.Columns.Add("属实");
                ReportHelper.myReportEnum.pLastTable.Columns.Add("不属实");

                #endregion
            }
        }
 */
        
    }
}
